package com.relax.mybatis.plugin.sensitive.strategy.impl;

import org.apache.commons.lang3.StringUtils;

import com.relax.mybatis.plugin.sensitive.strategy.SensitiveStrategy;

/**
 * @author relax
 * @date 2022/07/05
 * @desc 地址脱敏策略
 */
public class AddressSensitiveStrategy implements SensitiveStrategy {

    /**
     * <p>地址脱敏：隐藏最后八位</p>
     *
     * <pre>
     * AddressSensitiveStrategy.handle("天河区花城大道")                = "天河区花城大道"
     * AddressSensitiveStrategy.handle("天河区花城大道666号")           = "天河区********"
     * AddressSensitiveStrategy.handle("广东省广州市天河区花城大道666号") = "广东省广州市天河区********"
     * </pre>
     *
     * @param data
     * @param symbol
     * @return
     */
    @Override
    public String handle(String data, String symbol) {
        int length = StringUtils.length(data);
        if (length <= 8) {
            return data;
        }
        return StringUtils.rightPad(StringUtils.left(data, length - 8), length, symbol);
    }

}
